#ifndef DBCONTROL_H
#define DBCONTROL_H

#include <QObject>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QVariantList>

// 数据库操作
class DBControl : public QObject
{
    Q_OBJECT
public:
    explicit DBControl(QObject *parent = nullptr);
    ~DBControl();

    // 连接数据库，给QML调用
    Q_INVOKABLE bool connectDataBase(QString host, quint16 port, QString userName, QString password, QString dbName);
    Q_INVOKABLE QVariantList getDataBaseInfo();

    //根据SQL文件创建数据表
    Q_INVOKABLE QString createTables();

    // channelsdataprotocol表示填写SQL配置
    Q_INVOKABLE int modbusJson2DB();

    // topicinfo和hldkeymap表
    Q_INVOKABLE int topicInfo2DB();

    // hldkeymap表：工况点描述信息入库
    Q_INVOKABLE int msgPointDesc2DB();

private:
    int handleModbusCfg(QString filePath, QString fileName);
    int handleTopicInfo(QString filePath, QString fileName);

signals:

private:
    QSqlDatabase db;
    QSqlQuery m_query;
    bool m_connState;

    int ams_orderKey;
};

#endif // DBCONTROL_H
